<?php
header("content-type:text/html;charset==utf-8");
$dsn="mysql:host=127.0.0.1;dbname=1109;charset=utf8";
$pdo=new PDO($dsn,'root','root');
$id=$_POST['id'];
$sql="select s_stock from shoop where s_id=$id";
$res=$pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$redis= new Redis();
$redis->connect("127.0.0.1","6379");
for($i=1;$i<=$res[0]['s_stock'];$i++){
    $redis->lPush("data".$id,$i);
}
if($redis->lpop("data".$id)){
    $sql="update shoop set s_stock=s_stock-1 where s_id=$id";
    $info=$pdo->exec($sql);
    if($info){
        $data=array('code'=>1,"msg"=>"成功");
    }
}else{
    $data=array('code'=>0,"msg"=>"失败");
}
echo json_encode($data);